package com.gm.mygmc.crm.security.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.oval.ConstraintViolation;
import net.sf.oval.exceptions.ConstraintsViolatedException;

import org.springframework.stereotype.Service;

import com.gm.gmcore.annotation.GmAutowired;

import com.gm.mygmc.crm.base.BaseServiceImpl;
import com.gm.mygmc.crm.base.ResponseDTO;
import com.gm.mygmc.crm.security.dto.UserInfoDTO;
import com.gm.mygmc.crm.security.service.IUserService;

@GmAutowired
@Service("userService")
public class UserServiceImpl extends BaseServiceImpl implements IUserService {

	@Override
	public ResponseDTO login(String userName, String password) {
		
		Map<String,Object> resultMap = new HashMap<String, Object>();
		resultMap.put("result", true);
		
		responseDTO.setResultMap(resultMap);	
		return responseDTO;
	}

	@Override
	public ResponseDTO register(UserInfoDTO user) {

		Map<String,Object> resultMap = new HashMap<String, Object>();	
		
		// collect the constraint violations 
		List<ConstraintViolation> violations = validator.validate(user);
		if(violations.size() > 0){
			throw new ConstraintsViolatedException(violations);
		}
		
		resultMap.put("result", true);
		responseDTO.setResultMap(resultMap);
		return responseDTO;
	}
		
}
